HAL COMP migration: List of applicable concepts

This section provides information about the HAL COMP applicable architecture concepts.

Concepts for COMP

Concept

Description

Separation of initialization and configuration functions

The initialization has been split into two levels of functions:

  • HAL_COMP_Init: initializes the handle and links it to a COMP instance.

  • HAL_COMP_SetConfig: configures the common COMP settings (Comparator input plus, Comparator input minus, Comparator input hysteresis, Comparator output polarity, Comparator output trigger).

Removal and conversion of init structure to configuration structure

The init structure for the COMP has been removed from the handle and converted into hal_comp_config_t structure.

Renaming of the handle structure

The handle structure has been renamed to hal_comp_handle_t.

Renaming unitary init structures

The structure comp_InitTypeDef is no longer available and has been replaced by hal_comp_config_t, HAL_COMP_SetInputPlus, HAL_COMP_SetInputMinus, HAL_COMP_SetOutputBlanking …

Remove MspInit and MspDeInit callbacks

hal_comp_MspInit and hal_comp_MspDeInit are no longer available and have been replaced by a user sequence to initialize and configure the COMP.

Unitary configuration APIs

New APIs are available to Get and set COMP features.

Introduction of HAL user data set/get APIs

Two functions to set and get user data are available: HAL_COMP_SetUserData, HAL_COMP_GetUserData

Individual callback registration APIs replace global register and unregister functions

The callback registration is handled by specific functions for each COMP event. These functions are used to register callback functions for different COMP events.

HAL implementation with LL inline functions

HAL COMP APIs now rely on LL APIs rather than performing direct register access.

Define statements and enumerations redirected to LL equivalents

HAL COMP define statements and enumerations are based on LL define statements.

Removal of hardware-related macros in HAL2

All hardware macros have been removed from the HAL COMP driver, and equivalent services are ensured through the LL APIs.

Revised and optimized HAL state machine

The COMP now is managed by a global state machine .

Revised and optimized HAL API status returns

The HAL UART functions were updated to return:

  • HAL_INVALID_PARAM: in case of a NULL p_config structure pointer.

  • HAL_ERROR: in case of an error.

  • HAL_BUSY: in case of an ongoing process.

  • HAL_OK: in case of a successfully completed operation.

Revised and optimized HAL error management

Redesign the error handling mechanisms within the HAL to improve the detection, reporting, and handling of errors. This rework aims to provide more detailed and consistent error information.

Replaced TypeDef suffix with _t in type names

All TypeDef parts of the HAL COMP driver have been removed and replaced by _t.

Replaced multi-line macros with inline functions

For the HAL COMP driver, large macros have been replaced by inline functions to maintain code consistency, improve readability, and benefit from compiler optimization. Inline functions also offer better support for debugging and strict type management, reducing the risk of errors.

Replaced nonmodifiable pointers with const keywords

Const keywords have been added to non-modifiable pointers to ensure that either the pointer itself or the data it points to cannot be modified. This enhances code safety and readability, prevents unintended modifications, and renders code more robust and maintainable.

Assertion implementation and usage in HAL1

The parameters and state are checked using ASSERT_DBG_STATE and ASSERT_DBG_PARAM macros.

Merge HAL extension files with common ones and remove the EX prefix from APIs.

Only one HAL COMP header file remains and all macros, define statements, and functions from hal_comp_ex.h have been moved to hal_comp.h.

Remove stm32tnxx_ll_ppp.c files

The source file stm32_ll_comp.c has been removed.

Remove EXTI Intrinsic Management in System HAL Drivers; Let Users Rely on EXTI HAL Driver.

All EXTI intrinsic management within the system services has been removed and will now be handled through the EXTI HAL driver.

Split Peripheral Configuration from Start in System HAL Drivers.

The initialization has been split into two functions: one for initialization and one for starting.

Replace Finite Parameter Defines (Including PPP Instances) with Enum Types at HAL Levels.

Finite parameters (including COMP instances) have been converted into enumerated types (enums) at HAL level. This improves code readability, maintainability, and type safety.

Add HAL_PPP Prefix to All HAL Peripheral APIs (Defines, Macros, Types, and Functions).

HAL COMP resources and data structure start with the HAL_COMP.

Other HAL COMP changes

Concept

Consideration

Rework COMP Window mode

New Functionality: The HAL_COMP_WINDOW_SetHandle() API is introduced to link COMP handles for window mode operation.

  • Usage in HAL1: Window mode configuration and start required passing two separate HAL handles, corresponding to COMP1 and COMP2.

  • Usage in HAL2: An optimized approach is provided through a dedicated linking function. After linking the COMP1 handle to the COMP2 handle using HAL_COMP_WINDOW_SetHandle(), window mode APIs can be called with either the COMP1 or COMP2 handle, removing the need to pass both handles explicitly.